| Conditions | 7 |
| Paths | 3 |
| Total Lines | 81 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /* |
||
| 93 | displayPanels: function (data) { |
||
| 94 | var self = this; |
||
| 95 | |||
| 96 | var ak = Object.keys(data); |
||
| 97 | for (var i = 0; i < ak.length; i++) { |
||
| 98 | var title = data[ak[i]]['title']; |
||
| 99 | var nav = data[ak[i]]['navigation']; |
||
| 100 | |||
| 101 | var li = $('<li>', {class: (nav.options !== undefined) ? 'collapsible open' : ''}); |
||
| 102 | var aIcon = $('<a>', { |
||
| 103 | href: '#', |
||
| 104 | class: 'search_icon' |
||
| 105 | }); |
||
| 106 | aIcon.text(title); |
||
| 107 | |||
| 108 | var ul = $('<ul>'); |
||
| 109 | if (nav.options !== undefined) { |
||
| 110 | |||
| 111 | aIcon.on('click', function () { |
||
| 112 | var li = $(this).closest('li'); |
||
| 113 | if (li.hasClass('open')) { |
||
| 114 | li.removeClass('open'); |
||
| 115 | } else { |
||
| 116 | li.addClass('open'); |
||
| 117 | } |
||
| 118 | }); |
||
| 119 | |||
| 120 | for (var j = 0; j < nav.options.length; j++) { |
||
| 121 | var sub = nav.options[j]; |
||
| 122 | |||
| 123 | var subA = $('<a>', { |
||
| 124 | href: '#', |
||
| 125 | class: 'ulsub', |
||
| 126 | text: sub.title |
||
| 127 | }); |
||
| 128 | |||
| 129 | var subAInput; |
||
| 130 | if (sub.type === 'checkbox') { |
||
| 131 | subAInput = $('<input>', { |
||
| 132 | class: 'search_checkbox_sub', |
||
| 133 | type: 'checkbox', |
||
| 134 | 'data-option': sub.name |
||
| 135 | }); |
||
| 136 | subAInput.change(function () { |
||
| 137 | self.initSearch(); |
||
| 138 | }); |
||
| 139 | } |
||
| 140 | |||
| 141 | if (sub.type === 'input') { |
||
| 142 | subAInput = $('<input>', { |
||
| 143 | class: 'search_input_sub search_input_sub_' + sub.size, |
||
| 144 | type: 'text', |
||
| 145 | placeholder: sub.placeholder, |
||
| 146 | 'data-option': sub.name |
||
| 147 | }); |
||
| 148 | subAInput.on('input', function () { |
||
| 149 | self.initSearch(); |
||
| 150 | }); |
||
| 151 | } |
||
| 152 | |||
| 153 | ul.append($('<li>').append(subA).append(subAInput)); |
||
| 154 | } |
||
| 155 | } |
||
| 156 | |||
| 157 | li.append(aIcon); |
||
| 158 | var aInput = $('<input>', { |
||
| 159 | class: 'search_checkbox', |
||
| 160 | type: 'checkbox', |
||
| 161 | 'data-provider': ak[i] |
||
| 162 | }); |
||
| 163 | aInput.change(function () { |
||
| 164 | self.initSearch(); |
||
| 165 | }); |
||
| 166 | |||
| 167 | li.append(aInput); |
||
| 168 | li.append(ul); |
||
| 169 | |||
| 170 | elements.search_panels.append(li); |
||
| 171 | } |
||
| 172 | |||
| 173 | }, |
||
| 174 | |||
| 289 |